/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_ARCHIVEMANAGER_H
#define M_ARCHIVEMANAGER_H

#include "archive.h"
#include "types.h"

#include "singleton.h"

#include "refptr.h"

#include <map>
#include <string>

namespace Engine
{
	/**
	*   Manages archives. Cashes loaded, load new.
	*/
	class ArchiveManager: public Singleton<ArchiveManager>
	{
	public:
		typedef std::map<std::string, ArchiveFactoryPtr > FactoriesMap;
		typedef std::map<std::string, RefPtr<Archive> > ArchivesMap;

		/**
		*   Open file for reading;
		*   @param name files name;
		*/
		RefPtr<DataStream> ReadFile(const std::string& name) const;

		/**
		*   Add archive factory.
		*/
		void AddArchiveFactory(ArchiveFactoryPtr factory);

		/**
		*   Return archive for specified filename(directory) with required type.
		*   @param filename name of archive or directory.
		*   @param archiveType type of orchive.
		*/
		void AddPath( const std::string& filename, const std::string& archiveType);

	private:

		FactoriesMap m_factories;
		ArchivesMap  m_loadedArchives;
	};
}

#endif
